package view
{
	import flash.events.Event;
	
	import model.DataProxy;
	import model.ViewProxy;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class ProgressViewMediator extends Mediator implements IMediator
	{
		public static const NAME:String 				= "ProgressViewMediator";
		
		private var progressView:ProgressView;
		
		public function ProgressViewMediator( viewComponent:Object = null )
		{
			super( NAME, viewComponent );
		}
		
		override public function onRegister():void
		{
			progressView = new ProgressView();
			progressView.addEventListener( ProgressView.READY, progressViewReadyHandler );
			progressView.init( viewProxy.vo);
			
			progressView.x = viewProxy.vo.FOOTER_WIDTH;
			progressView.y = viewProxy.vo.LOGIN_HEIGHT;
			
			viewProxy.vo.progressView = progressView;
			
			viewComponent.addChild( progressView );
		}
		
		override public function listNotificationInterests():Array
		{
			return [ ProgressView.SHOW, ProgressView.HIDE ];
		}
		
		override public function handleNotification( notification:INotification ):void
		{
			var name:String = notification.getName();
			var body:Object = notification.getBody();
			
			switch( name )
			{
				case ProgressView.SHOW:
					progressView.show( body.txt );
					break;
				case ProgressView.HIDE:
					progressView.hide( body.txt );
					break;
			}
		}
		
		private function progressViewReadyHandler( e:Event ):void
		{
			sendNotification( ProgressView.READY );
		}
		
		private function get dataProxy():DataProxy
		{
			return facade.retrieveProxy( DataProxy.NAME) as DataProxy;
		}
		
		private function get viewProxy():ViewProxy
		{
			return facade.retrieveProxy( ViewProxy.NAME	) as ViewProxy;
		}
	}
}